/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.voidness.oje2d.tests;

import org.voidness.oje2d.Timer;
import org.lwjgl.input.Keyboard;
import org.voidness.oje2d.Engine;
import org.voidness.oje2d.GLColor;
import org.voidness.oje2d.GLFont;
import org.voidness.oje2d.GLImage;
import org.voidness.oje2d.Timer.TimerCallback;
import org.voidness.oje2d.interfaces.EngineInterface;
import org.voidness.oje2d.particlesystems.GLParticleSystemRing;

/**
 *
 * @author void
 */
public class SimplerEngineTest implements EngineInterface {

    private Engine engine;
    private GLFont font;
    private GLImage crate;
    private GLParticleSystemRing particleRing;
    private float angle;
    private Timer timer;

    public SimplerEngineTest() {

        angle = 0.0f;
        engine = Engine.getInstance();
        engine.init(640, 480, 32, false, this);
        engine.start();
    }

    public void init() {

        // This is where you initialize your stuff (resources, objects, etc.)
        font = new GLFont("resources/fonts/tahoma.png", 1.0f);
        crate = new GLImage("resources/images/crate.jpg", 50, 50, false);
        particleRing = new GLParticleSystemRing();
        particleRing.initParticles("resources/images/particle.png", 100);
        particleRing.setRadius(90, 200);
        particleRing.setSpeed(0.5f, 5);
        particleRing.setTimeToLive(5000, 10000);
        particleRing.setLoop(true);
        particleRing.start();

        timer = new Timer();
        timer.addCallback(new TimerCallback() {

            public void onTick(long elapsedTime) {

                // 360 degrees (full turn) per second
                angle += 360.0f * elapsedTime / 1000.0f;
                if (angle > 360.0f) {

                    angle = 0.0f;
                }
                if (angle < 0.0f) {

                    angle = 360.0f;
                }
            }
        });
    }

    public void logic() {

        // Called by the engine every cycle. You can put your logic here.

        timer.tick();
    }

    public void render() {

        // This is where you should render your images

        for (int i = 0; i < 640; i += 50) {
            for (int j = 0; j < 480; j += 50) {
                //crate.draw(i, j);
            }
        }

        crate.drawRotated(100, 100, angle);

        //particleRing.draw(300, 300);

        font.print("FPS: " + engine.getFPS(), 10, 10, 1.0f, GLColor.WHITE);
        font.print("Mouse: " + engine.getMouseX() + "," + engine.getMouseY(),
                10, 25, 1.0f, GLColor.YELLOW);
    }

    public void onEngineExit() {

        // Before exiting, the engine will call this method
    }

    public void keyPressed(int eventKey, char eventCharacter) {

        // When a key is pressed, this is called
    }

    public void keyReleased(int eventKey, char eventCharacter) {

        // When a key is released, this is called

        if (eventKey == Keyboard.KEY_ESCAPE) {

            engine.destroy();
            System.exit(0);
        }
    }

    public void mousePressed(int mButton) {

        // Everytime a mouse button is pressed, this is called
    }

    public void mouseReleased(int mButton) {

        // Everytime a mouse button is released, this is called
    }

    public static void main(String[] args) {

        // Don't forget the java.library.path on your run configuration. It 
        // needs to point to wherever you have your LWJGL binaries.
        // Something like this:
        // -Djava.library.path=/Users/void/Development/lwjgl-2.1.0/native/macosx
        new SimplerEngineTest();
    }
}
